package com.cnzhy.session;

import com.cnzhy.binding.MyMapperProxy;
import com.cnzhy.executor.MyBaseExecutor;

import java.lang.reflect.Proxy;

public class MySqlSession {

    private final MyBaseExecutor executor = new MyBaseExecutor();

    public <T> T selectOne(String statement, Object parameter) {
        return executor.query(statement, parameter);
    }

    public <T> T getMapper(Class<T> clazz) {
        // 动态代理调用
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new MyMapperProxy(this));
    }

}
